package cn.demographic.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import cn.demographic.entity.Registry;
import cn.demographic.entity.User;
import cn.demographic.service.WorkingconditionsService;

@RestController
@RequestMapping("/RegistrationInformation")
public class RegistrationInformationController {
	@Autowired
	private WorkingconditionsService workingconditionsService;

	/**
	 * 录用信息审核的数据
	 * @return
	 */
	@RequestMapping("/selectByUserByAppByEmpl")
	@ResponseBody
	public Map<String,Object> selectByUserByAppByEmpl(String unit,String name,String phone,String status,String stateTime,
			String endTime,String pageNoStr,String pageSizeStr,HttpSession session){
		//获取参数
		long pageNo = 1; //如果没有传数据,默认为第一页
		if( pageNoStr != null && pageNoStr.trim().length()>0 ){
			pageNo = Long.parseLong(pageNoStr);
		}
		int pageSize = 5; //如果没有传数据,默认为10条数据
		if( pageSizeStr != null && pageSizeStr.trim().length()>0 ){
			pageSize = Integer.parseInt(pageSizeStr);
		}
		long beginNo = (pageNo-1)*pageSize;
		//获取地址，市级
		Registry registry = (Registry) session.getAttribute("registry");
		Map<String,Object> mapList = new HashMap<String, Object>();
		mapList.put("liveCity", registry.getLive().getCity() );
		mapList.put("unit", unit);
		mapList.put("name", name);
		mapList.put("phone", phone);
		mapList.put("status", status);
		mapList.put("stateTime", stateTime);
		mapList.put("endTime", endTime);
		mapList.put("beginNo", beginNo);
		mapList.put("pageSize", pageSize);
		List<User> users = workingconditionsService.selectUser(mapList);
		Long count = workingconditionsService.countUser(mapList);
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("users", users);
		map.put("count", count);
		return map;	
	}

	/**
	 * 修改审核数据
	 * @param userid
	 * @param status
	 * @return
	 */
	@RequestMapping("/updetApplicanttable")
	@ResponseBody
	public Integer updetApplicanttable(Integer[] userid, Integer status, String state) {
		Integer[] id = new Integer[userid.length-1];
		for (int i = 0; i < id.length; i++) {
			id[i] = userid[i];
		}
		Integer appl = workingconditionsService.updetApplicanttable(id, status, state);
		return appl;
	}

	
}
